package study.lxy.dubbo_ecif.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import study.lxy.dubbo_api.api.ecif.CreateEcifService;
import study.lxy.dubbo_api.entity.CustInfo;
import study.lxy.dubbo_api.exception.BusiException;
import study.lxy.dubbo_ecif.mapper.CustInfoMapper;

@RestController
@RequestMapping(value="/cust")
public class CustController {
	
	@Autowired
	private CreateEcifService createService;
	@Autowired
	private CustInfoMapper mapper;
	
	@RequestMapping(value="/hello",method=RequestMethod.GET)
	public String hello() {
		return "Hello";
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public CustInfo findById(@PathVariable String id) {
		System.out.println("insild");
		CustInfo custInfo = mapper.selectByPrimaryKey(id);
		System.out.println("name : " + custInfo.getCustName());
		System.out.println("address : " + custInfo.getAddress());
		return custInfo;
	}
	
	@RequestMapping(value="/",method=RequestMethod.POST)
	public String insertCustInfo(@ModelAttribute CustInfo custInfo) {
		
		try {
			System.out.println("createService : " + createService);
			System.out.println("name : " + custInfo.getCustName());
			System.out.println("address : " + custInfo.getAddress());
			custInfo = createService.create(custInfo);
		} catch (BusiException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return custInfo.getEcifId();
		
	}

}
